<?php

/**
 * Created by PhpStorm.
 * User: d7
 * Date: 2016/1/23
 * Time: 9:53
 */
class Helper extends MY_Admin_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Helper_model');
        $this->assign('index_channel','marketing');
    }

    function index($page=1){
        $offset = ($page-1)*20;
        $count = $this->Helper_model->get_counts();
        $helpers = $this->Helper_model->gets(20,$offset);
        $ids = array_column($helpers,'_id');
        foreach($helpers as &$value){
            $value['id'] = array_pop($ids);
        }
        $this->assign('helpers',$helpers);
        $this->assign('page',$page);
        $this->assign('count',$count);
        $this->assign('now_url',site_url('m-admin/helper/index'));
        $this->display();
    }

    function add(){
        $this->display();
    }
    function save(){
        if($this->input->post('action')=='add'){
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            $account = $this->input->post('account');
            $type = $this->input->post('type');

            if($this->Helper_model->insert(
                array(
                    'username'  =>  $username,
                    'password'  =>  $password,
                    'account'   =>  $account,
                    'type'      =>  $type,
                    'last_busy_time'    =>  ' ',
                    'busy'      =>  intval(0)
                )
            )){
                $this->json_response(true);
            }
        }
        $this->json_response(false);
    }

    function edit(){
        $this->display();
    }
}